import { ICardItem } from '../type';
import data1 from './data1.json'
import data2 from './data2.json'

const colorArr = ["#409eff", "#67c23a", "#e6a23c", "#f56c6c", "#909399"];

interface IDataList {
    data: {
        items: ICardItem[];
    };
}

function formatData(dataList: IDataList): ICardItem[] {
    return dataList.data.items.map((item) => ({
        id: item.id,
        width: item.note_card.cover.width,
        height: item.note_card.cover.height,
        title: item.note_card.display_title,
        author: item.note_card.user.nick_name,
        img_url: item.note_card.cover.url,
    }))
}

const list: ICardItem[] = [data1, data2].map((item: any) => {
    const formattedData = formatData(item);
    return formattedData.map((data, dataIndex: number) => ({ ...data, bgColor: colorArr[dataIndex % (colorArr.length - 1)] }))
}).flat()

export default list